#include "Avalon/IO/ConnectionState.hpp"

using namespace Avalon;
using namespace Avalon::IO;
using namespace boost;
using namespace boost::signals2;

ConnectionState::ConnectionState()
    : m_isOpen(false) {}

ConnectionState::~ConnectionState() {
  assert(!m_isOpen);
  assert(!m_closedConnection.connected());
}

void ConnectionState::Initialize(bool isOpen,
    const connection& closedConnection) {
  assert(!m_isOpen);
  if(!isOpen) {
    closedConnection.disconnect();
    return;
  }
  m_isOpen = true;
  m_closedConnection = closedConnection;
}

bool ConnectionState::IsOpen() const {
  return m_isOpen;
}

void ConnectionState::SetClosed() {
  m_isOpen = false;
  m_closedConnection.disconnect();
}
